import CCNodePool from "./CCNodePool";

export default class SelfPool {

    private list:cc.Node[] = []
    
    private pool:CCNodePool;

    constructor(pool:CCNodePool){
        this.pool = pool;
    }

    get(){
        let go:cc.Node =  this.list.length > 0 ? this.list.shift() : this.pool.get();
        go.opacity  = 255;
        return go;     
    }

    getPool(){
        return this.pool
    }

    size(){
        return this.pool.size() + this.list.length;
    }

    put(go:cc.Node,nodePool:boolean = false){
        if(nodePool){
            this.pool.put(go)
        }else{
            this.list.push(go);
           
            go.stopAllActions();
            go.opacity  = 0;
        }

    }

    clear(){
        this.pool.clear();
        this.list.length = 0;     
    }
}
